package spindles.gwt.client;

import java.util.HashMap;
import java.util.Map;

import spindles.gwt.client.TableData.Row;
import spindles.gwt.shared.DTO;
import spindles.gwt.shared.SettingsDTO;
import spindles.gwt.shared.UserDTO;

public class Registry {
	
	private static Registry instance = new Registry();
	
	private Map registry = new HashMap();
	
	private Registry(){}
	
	public static void setUser(UserDTO user){
		instance.registry.put("user", user);
	}
	
	public static UserDTO getUser(){
		return (UserDTO) instance.registry.get("user");
	}
	
	public static void addDTO(DTO dto){		
		instance.registry.put(dto.getId(), dto);		
	}
	
	public static DTO getDTO(String id){
		return (DTO)instance.registry.get(id);
	}
	
	public static boolean withSoftCriterion(){
		return ((Boolean)instance.registry.get("soft")).booleanValue();
	}
	
	public static void setCriterion(boolean soft){
		instance.registry.put("soft", Boolean.valueOf(soft));
	}
	
	public static void setShowRawEEG(boolean raw){
		instance.registry.put("raw", Boolean.valueOf(raw));
	}
	
	public static void setMasterRecord(Row rec){
		instance.registry.put("masterRecord", rec);
	}
	
	public static Row getMasterRecord(){
		return (Row)instance.registry.get("masterRecord");
	}
	
	public static boolean showRawEEG(){
		Boolean raw = (Boolean)instance.registry.get("raw");
		return raw != null ? raw.booleanValue() : false;
	}
	
	public static void setSettings(SettingsDTO dto){
		instance.registry.put("settings", dto);
		setShowRawEEG(dto.isShowOnlyRawData());
	}
	
	public static SettingsDTO getSettings(){
		return (SettingsDTO)instance.registry.get("settings");
	}

}
